package com.tc.data.test.strategy.repository;

import com.tc.data.common.strategy.repository.RepositoryShardingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseRepositoryShardingStrategy extends RepositoryShardingStrategy {

	private final Logger logger = LoggerFactory.getLogger(BaseRepositoryShardingStrategy.class);
	
	@Override
	public String getReadWriteDataSource(Object obj) {
		try {
			String dbNm = doGetReadWriteDataSource(obj);
			logger.info("Use db {} by strategy: {}", dbNm, getClass().getName());
			return dbNm;
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new IllegalArgumentException(e.getMessage(), e);
		}
	}
	
	protected abstract String doGetReadWriteDataSource(Object obj);
	
}
